﻿using System;
using System.IO;
using System.Windows;
using System.Windows.Data;
using System.Windows.Documents;

namespace WpfTwitterClient.Modules.Timelines
{
    [ValueConversion(typeof(FlowDocument), typeof(string))]
    public class RtfToFlowDocumentConverter : IValueConverter
    {
        #region IValueConverter Members

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            var document = new FlowDocument();
            var range = new TextRange(document.ContentStart, document.ContentEnd);
            Stream stream = value as Stream; // implement this method to get memorystream from the value which is ur rtf data.
            range.Load(stream, DataFormats.Rtf);
            return document ;
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            return null;
        }

        #endregion
    }

}
